<?php
	class SearchKhachSan extends CI_Controller 
	{
	    function getCountry() 
		{
        	$this->load->model('khachsan_model');
	        $data['country'] = $this->khachsan_model->layQuocGia();
    	    $this->load->view('home/ThanhPho_Quan_view', $data);
	    }

    	function getCityByCountry() 
		{
			$country = $this->input->post('quocgia');
			$this->load->model('khachsan_model');
			$data['city'] = $this->khachsan_model->TimThanhPho($country);
			$data['country'] = $this->khachsan_model->layQuocGia();
			$data['countryname'] = $this->input->post('quocgia');
			$data['choice'] = $this->input->post('choice');
			$this->load->view('home/ThanhPho_Quan_view', $data);
    	}

	    function getRegionByCity() 
		{
			$city = $this->input->post('thanhpho');
			$country = $this->input->post('quocgia');
			$this->load->model('khachsan_model');
			$data['Region'] = $this->khachsan_model->TimQuan($city);
	
			$data['country'] = $this->khachsan_model->layQuocGia();
			$data['countryname'] = $this->input->post('quocgia');
	
			$data['city'] = $this->khachsan_model->TimThanhPho($country);
			$data['cityname'] = $this->input->post('thanhpho');
	
			$data['choice'] = $this->input->post('choice');
			$this->load->view('home/ThanhPho_Quan_view', $data);
    	}

	    function search_Hotel() 
		{
			$quick_search = $this->input->post('searchname');
			$country = $this->input->post('qg');
			$city = $this->input->post('tp');
			$region = $this->input->post('kv');
			$dateCheckin = $this->input->post('date');
			$tieuchi = array($country, $city, $region, $dateCheckin);
	
			$this->load->model('khachsan_model');
			$data['country'] = $this->khachsan_model->layQuocGia();
			$data['select_date'] = $dateCheckin;
			
			if ($quick_search != "Nhập tên thành phố hoặc tên khách sạn...") 
			{
				$data['DSKhachSan'] = $this->khachsan_model->TimKhachSanNhanh($quick_search, $dateCheckin);
				$data['region'] = NULL;				
				
				$data['select_hotel'] = $quick_search;
				$data['select_country'] = NULL;
				$data['select_city'] = NULL;
				$data['select_region'] = NULL;
			}
			else
			{ 
				$data['DSKhachSan'] = $this->khachsan_model->TimKhachSanTuyChon($tieuchi);
				
				$data['city'] = $this->khachsan_model->TimThanhPho($country);
				$data['region'] = $this->khachsan_model->TimQuan($city);
				
				$data['select_hotel'] = "Nhập tên thành phố hoặc tên khách sạn...";				
				$data['select_country'] = $country;
				$data['select_city'] = $city;
				$data['select_region'] = $region;
			}
	
			$this->load->view('home/SearchKS_view', $data);
	    }
	}
?>